<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSelected"
    @cancel="close"
    style="top:50px"
    cancelText="关闭"
  >
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="分类名称">
                <a-input placeholder="请输入分类名称" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button
                  type="primary"
                  @click="searchReset"
                  icon="reload"
                  style="margin-left: 8px"
                >重置</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->
      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
          <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          class="j-table-force-nowrap1"
          @change="handleTableChange"
        ></a-table>
      </div>
    </a-card>
  </j-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'SelectGoodsClassificationListModal',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  props: {
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
  },
  data() {
    return {
      description: '物料分类查询页面',
      visible: false,
      title: '选择物料分类',
      queryParam: {},
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '物料分类编号',
          align: 'center',
          dataIndex: 'categoryNo',
        },
        {
          title: '物料分类名称',
          align: 'center',
          dataIndex: 'name',
        },

        {
          title: '管理方式',
          align: 'center',
          dataIndex: 'categoryManageType_dictText',
        },
      ],
      url: {
        list: '/erp/base/erpGoodsClassification/list',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  methods: {
    handleSelected() {
      let selectedRow = null
      if (this.checkval == 'radio') {
        selectedRow = this.selectionRows
      } else {
        selectedRow = this.selectionRows
      }
      // let selectedRow = this.selectionRows[0];
      //传递选中的数据
      this.$emit('selectGoodsClassificationOk', selectedRow)
      this.close()
    },
    showModal() {
      this.visible = true
      this.loadData()
    },
    initDictConfig() {},
    close() {
      this.searchReset(false)
      this.visible = false
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'name', text: '分类名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'categoryNo', text: '分类编号', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'categoryManageType',
        text: '管理方式',
        dictCode: 'material_manage_type',
      })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>